package com.gdlgxy.oa.DAO;

import com.gdlgxy.oa.bean.Fare;
import com.gdlgxy.oa.bean.FareList;
import com.gdlgxy.oa.utils.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.TreeMap;

/**
 * 获取数据库中的支出类型
 */
public class KindListDao implements Dao{
    /**
     * 通过数据库获取学生对应的支出
     * @return 学生链表
     */
    public static TreeMap<Integer,String> getKindList(){
        // 创建支出类型的哈希集合
        TreeMap<Integer,String> map = new TreeMap<>();

        // 连接数据库，查询当前数据库的支出类型
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            conn = DBUtil.getConnection();
            String sql = "SELECT Kno,Kname FROM t_kind";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();

            while (rs.next()) {
                int Kno = rs.getInt("Kno");
                String Kname = rs.getString("Kname");
                map.put(Kno,Kname);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(conn, ps, rs);
        }

        return map;
    }
}
